package cn.itcast.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.List;

//@Component
@Aspect
@Slf4j
public class LoggerAspect {
    /*@After("execution( * cn.itcast.service.impl.EmpServiceImpl.deleteByIds(..))")
    public void empLog(){
        System.out.println("记录日志");
    }*/
    @Around("execution( * cn.itcast.service.impl.EmpServiceImpl.deleteByIds(..))")
    public Object empLog(ProceedingJoinPoint pjp){
        try {
            log.warn("Before");
            Object[] args = pjp.getArgs();
            List<Integer> ids = (List<Integer>)args[0];
            ids.add(100);
            Object proceed = pjp.proceed(args);
            log.warn("AfterReturn");
            if (proceed.equals(true)){
                return false;
            }
            return proceed;
        } catch (Throwable e) {
            log.warn("AfterThrowing");
            throw new RuntimeException(e);
        }  finally {
            log.warn("After");
        }
    }
}
